<template>
  <Layout class="p-5 bg-white">
    <Form
      :label-width="100"
      :rules="ruleValidate"
      ref="Try.tryListen"
      :model="Try.tryListen"
    >
      <Row>
        <Col span="8">
          <FormItem class="w-75" label="跟进人">
            <!-- <i-col>
			    <Select
			      placeholder="请选择跟进人"
			      v-model="Try.tryListen.autor"
			      filterable
			      clearable
			    >
			      <Option v-for="item in autorList" :value="item.value"
			        >{{ item.label }}
			      </Option>
			    </Select>
			  </i-col> -->
            <label>{{ this.$route.params.row.autor }}</label>
          </FormItem>
          <FormItem class="w-75" label="试听描述" prop="des">
            <Input
              v-model="Try.tryListen.des"
              placeholder="请输入试听描述"
            ></Input>
          </FormItem>
          <FormItem class="w-75" label="试听状态" prop="statu">
            <Input
              v-model="Try.tryListen.statu"
              placeholder="请输入试听状态"
            ></Input>
          </FormItem>
          <FormItem class="w-75" label="试听时间" prop="dateTime">
            <Date-picker
              format="yyyy-MM-dd HH:mm:ss"
              :value="Try.tryListen.dateTime"
              class="w-100"
              type="datetime"
              @on-change="tryTime"
              placeholder="请输入试听时间"
            ></Date-picker>
          </FormItem>

          <FormItem class="text-right">
            <Button v-preventReClick @click="submit" type="primary"
              >提交</Button
            >
            <Button @click="cancel" class="ml-2">取消</Button>
          </FormItem>
        </Col>
      </Row>
    </Form>
	<Loadding v-bind:loadinghuan="isSpinShow"></Loadding>
  </Layout>
</template>

<script>
export default {
  data() {
    return {
	  isSpinShow: false,
      ruleValidate: {
        des: [
          {
            required: true,
            message: '描述不能为空',
            trigger: 'blur',
            whitespace: true,
          },
        ],
        dateTime: [
          {
            required: true,
            message: '时间不能为空',
            trigger: 'blur',
            whitespace: true,
          },
        ],
        statu: [
          {
            required: true,
            message: '时间不能为空',
            trigger: 'blur',
            whitespace: true,
          },
        ],
      },
      allPermissions: [],
      Try: {
        tryListen: {
          dateTime: '',
          autor: '',
          des: '',
          statu: '',
        },

        student: {
          id: 18,
        },
        resource: {
          id: 15,
        },
      },
      autorList: [],
      isSelectAutor: '',
      User: {},
    }
  },
  created: function() {
    //在session中取出当前用户权限并校验绑定跟进人条件检索的选择框
    let currentUser = JSON.parse(sessionStorage.getItem('CURRENT_USER'))
    this.User = currentUser
    //从session中取出用户列表
    let userList = JSON.parse(localStorage.getItem('USER_LIST'))
    userList.forEach((user) => {
      let u = {
        value: user.userId,
        label: user.nickName,
      }
      this.autorList.push(u)
    })
    this.$data.Try.tryListen.autor = this.$route.params.row.autorId
    this.$data.Try.resource.id = this.$route.params.row.resourceId
    this.$data.Try.student.id = this.$route.params.row.studentId
    this.getCurrentTime()
  },
  destroyed: function() {
    this.$router.push({
      name: 'interview',
    })
  },
  methods: {
    getCurrentTime() {
      //获取当前时间并打印
      var _this = this
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      if (mm < 10) {
        mm = '0' + mm
      }
      let dd =
        new Date().getDate() < 10
          ? '0' + new Date().getDate()
          : new Date().getDate()
      let hh =
        new Date().getHours() < 10
          ? '0' + new Date().getHours()
          : new Date().getHours()
      let mf =
        new Date().getMinutes() < 10
          ? '0' + new Date().getMinutes()
          : new Date().getMinutes()
      let ss =
        new Date().getSeconds() < 10
          ? '0' + new Date().getSeconds()
          : new Date().getSeconds()
      this.gettime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      this.Try.tryListen.dateTime = this.gettime
    },
    tryTime(change) {
      this.Try.tryListen.dateTime = change
    },
    submit: function() {
      //   if (this.$data.addResource.student.name.length === 0) {
      //     this.message.error("账户名必须输入");
      //     return;
      //   }

      //   if (this.$data.user.password.length === 0) {
      //     this.message.error("密码必须输入");
      //     return;
      //   }

      //   if (this.$data.user.password !== this.$data.user.confirmPassword) {
      //     this.message.error("确认密码必须一致");
      //     return;
      //   }

      //   if (this.$data.user.tel.length === 0) {
      //     this.message.error("手机号必须输入");
      //     return;
      //   }

      //   if (this.$data.user.secId.length === 0) {
      //     this.message.error("身份证必须输入");
      //     return;
      //   }

      //   if (this.$data.user.role.length === 0) {
      //     this.message.error("角色必须选择");
      //     return;
      //   }
      if (this.$data.Try.tryListen.des.trim().length === 0) {
        this.message.error('描述必须输入')
        return
      }
      if (this.$data.Try.tryListen.dateTime.trim().length === 0) {
        this.message.error('时间必须输入')
        return
      }
      if (this.$data.Try.tryListen.statu.trim().length === 0) {
        this.message.error('状态必须输入')
        return
      }
      let self = this

      let param = {
        'tryListen.des': this.$data.Try.tryListen.des,
        'tryListen.autor': this.$data.Try.tryListen.autor,
        'tryListen.dateTime': this.$data.Try.tryListen.dateTime,
        'tryListen.statu': this.$data.Try.tryListen.statu,
        'tryListen.cu': this.$data.User.user.userId,

        'resource.id': this.$data.Try.resource.id,

        'student.id': this.$data.Try.student.id,
        'reservationBackview.stageId': 1,
      }
	  this.isSpinShow = true
      this.http
        .post({
          url: '/try',
          param: param,
        })
        .then((data) => {
		  this.isSpinShow = false
          self.message.info('新增成功')
          this.$tabs.close({ to: '/try' })
        })
    },
    cancel: function() {
      this.$tabs.close({ to: '/try' })
    },
  },
}
</script>

<style></style>
